#include "./status_task.h"
#include "../driver/mux.h"
#include "../driver/nozzle_motor.h"
#include "../driver/sensor.h"
#include "../driver/cmd_uart.h"
#include "../conn/proto.h"
#include "../driver/analog.h"
#include "../driver/parts.h"
#include "./draw_task.h"
#include "./heat_task.h"

namespace task {

using namespace driver;
using namespace conn;

constexpr uint16_t APP_VERSION = 0x0010;

void StatusTask::run() {

    for (;;) {

        sensor->read_all_temp();

        uint8_t sen = (sensor->is_leak()) +
            (sensor->is_steam_high() << 1) +
            (sensor->is_steam_low() << 2) +
            (sensor->is_steam_ok() << 3) +
            (nozzleMotor->is_alm() << 4)
            ;

        cmdUart->write_notify(
            notify::STATUS,
            APP_VERSION,
            mux->status(),
            sen,
            analog->kpa_value(),
            sensor->steam_value(),
            sensor->flow_count(),
            analog->current_value(),
            parts->status(),
            drawTask->state(),
            heatTask->state()
        );  

        osDelay(500);

    }
}

}
